package rs.fon.is.music.services.rest.parsers;

import rs.fon.is.music.domain.MusicAlbum;

import com.google.gson.JsonObject;

public class MusicAlbumJsonParser {

	public static JsonObject serialize(MusicAlbum album) {
		JsonObject albumJson = new JsonObject();
		String uri = album.getUri().toString();
		albumJson.addProperty("uri", uri);
		albumJson.addProperty("url", album.getUrl().toString());
		albumJson.addProperty("name", album.getName());
		if(album.getImage()!=null)
			albumJson.addProperty("image", album.getImage().toString());
		albumJson.addProperty("numTracks", album.getNumTracks());
		albumJson.addProperty("interactionCount", album.getInteractionCount());
		if(album.getKeywords().size()>0){
			String keywords = "";
			for (String keyword : album.getKeywords()) {
				keywords += keyword + ", ";
			}
			albumJson.addProperty("keywords", keywords.substring(0, keywords.length()-2));
		}
		String albumID = uri.substring(uri.lastIndexOf('/')+1);
		String groupID = album.getArtist().getUri().toString().substring(album.getArtist().getUri().toString().lastIndexOf('/')+1);
		albumJson.addProperty("byArtist", "http://localhost:8080/Music/api/groups/" + groupID);
		albumJson.addProperty("tracks", "http://localhost:8080/Music/api/albums/" + albumID + "/recordings");
		return albumJson;
	}

}
